package cn.yyx.customerservice.controller;


import cn.yyx.common.R;
import cn.yyx.customerservice.OssUtil;
import cn.yyx.customerservice.entity.CustomerImg;
import cn.yyx.customerservice.service.impl.CustomerImgServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lsj
 * @since 2023-10-25
 */
@RestController
@RequestMapping("/eduoss")

public class CustomerImgController {

    @Autowired
    private CustomerImgServiceImpl imgService;



    @PostMapping("customer/fileoss")
    public R customerFile(@RequestBody MultipartFile file) {
        System.out.println(file);
        String s = (UUID.randomUUID().toString()).replaceAll("-","")+".jpg";
        String[] s1 = s.split("\\?");
        System.out.println(s1[0]);
        String i = OssUtil.uploadObject2OSS(OssUtil.OSS_CLIENT,file,OssUtil.BUCKET_NAME,s1[0],OssUtil.FOLDER);
        System.out.println("I:"+i);
        return R.ok().data("url",i);
    }
}

